package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.zzw.BO.DeptBO;
import com.ruoyi.common.core.domain.zzw.TDepartmentManage;
import com.ruoyi.common.core.domain.zzw.TPeopleManage;
import com.ruoyi.common.core.domain.zzw.VO.*;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.TRescueStrengthMapper;
import com.ruoyi.system.service.TRescueStrengthService;
import org.apache.commons.collections4.map.LinkedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class TRescueStrengthServiceImpl implements TRescueStrengthService {
    @Autowired
    private TRescueStrengthMapper tRescueStrengthMapper;

    @Override
    public getRescueListVO getRescueList() {
        return tRescueStrengthMapper.getRescueList();
    }

    @Override
    public AjaxResult getListByDept(String cdepartmentId) {
        DeptBO deptBO=new DeptBO();
        deptBO.setDepartmentId(cdepartmentId);
        List<TPeopleManage> leaders  =tRescueStrengthMapper.getLeadersByDept(deptBO);
        List<TPeopleManage> dutys  =tRescueStrengthMapper.getDutysByDept(deptBO);
        GetPeopleListByDeptVO vo=new GetPeopleListByDeptVO();
        vo.setLeaders(leaders);
        vo.setDutys(dutys);
        return AjaxResult.success(vo);
    }

    @Override
    public AjaxResult DeptType() {
        DeptBO deptBO=new DeptBO();
        LinkedMap<String,List<TDepartmentManageVO>> maps=new LinkedMap<>();
        List<TDepartmentManageVO>  deptTop= tRescueStrengthMapper.getDeptTop();
        maps.put("指挥长",deptTop);
        for (TDepartmentManageVO departmentManage : deptTop) {
            deptBO.setDepartmentType(departmentManage.getCDepartmentType());
            deptBO.setPid(String.valueOf(departmentManage.getCDepartmentId()));
            List<TDepartmentManageVO>  vo= tRescueStrengthMapper.getDeptByType(deptBO);
            maps.put(departmentManage.getCDepartmentName(),vo);
        }
        return AjaxResult.success(maps);
        //父级
//        List<TDepartmentLsitVO>  deptTop= tRescueStrengthMapper.getDeptTop();
//        TDepartmentLsitVO peopleLear=new TDepartmentLsitVO();
//        peopleLear.setLabel("指挥长");
//        peopleLear.setId(0L);
//        deptTop.add(peopleLear);
//        //所有的指挥长
//        List<TDepartmentLsitVO> leaders = tRescueStrengthMapper.selectLeaders();
//        //所有的值班长
//        List<TDepartmentLsitVO> dutys = tRescueStrengthMapper.selectDutys();
//        //所有的部门信息
//        List<TDepartmentLsitVO> childs = tRescueStrengthMapper.selectChild(null);
//
//        List<TDepartmentLsitVO> lsitVOS = deptTop.stream().map(item -> {
//
//            List<TDepartmentLsitVO> child = childs.stream()
//                    .filter(lea -> lea.getCPid().equals(String.valueOf(item.getId())))
//                    .collect(Collectors.toList());
//
//            List<TDepartmentLsitVO> collect = child.stream().map(map -> {
//                //
//                List<TDepartmentLsitVO> zhzList=new ArrayList<>();
//
//                TDepartmentLsitVO zhz=new TDepartmentLsitVO();
//                zhz.setLabel("指挥长");
//                TDepartmentLsitVO zbz=new TDepartmentLsitVO();
//                zbz.setLabel("值班长");
//                List<TDepartmentLsitVO> leader = leaders.stream()
//                        .filter(lea -> Objects.equals(lea.getCDepartmentId(), map.getId()))
//                        .collect(Collectors.toList());
//                    List<TDepartmentLsitVO> duty = dutys.stream()
//                            .filter(dut -> Objects.equals(dut.getCDepartmentId(), map.getId()))
//                            .collect(Collectors.toList());
//                    zbz.setChild(duty);
//                zhz.setChild(leader);
//                zhzList.add(zhz);
//                zhzList.add(zbz);
//                map.setChild(zhzList);
//                return map;
//
//            }).collect(Collectors.toList());
//
//            item.setChild(collect);
//            return item;
//        }).collect(Collectors.toList());
//    return AjaxResult.success(lsitVOS);
    }

    @Override
    public AjaxResult getLeaderTop() {
        DeptBO deptBO =new DeptBO();
        if (StringUtils.isNotEmpty(deptBO.getPid())){
            deptBO.setPid("0");
        }
       List<TPeopleManageVO>  vo=tRescueStrengthMapper.getLeaderTop(deptBO);
        return AjaxResult.success(vo);
    }
}
